import { lazy, createRef } from "react";
import { Navigate } from "react-router-dom";
import LayoutIndex from "@/layout";

const routes = [
  {
    path: "/login",
    component: lazy(() => import("@/views/login/Login")),
    nodeRef: createRef(null),
  },
  {
    path: "/",
    component: () => <Navigate to="/home"></Navigate>,
    nodeRef: createRef(null),
  },
  {
    name: "Home",
    path: "/",
    component: LayoutIndex,
    nodeRef: createRef(null),
    meta: {
      order: 0,
    },
    children: [
      {
        path: "/home",
        component: lazy(() => import("@/views/home")),
        nodeRef: createRef(null),
        meta: {
          title: "首页",
          icon: "ic:sharp-home",
          order: 0,
        },
      },
    ],
  },
  //重定向
  {
    path: "/article",
    component: () => <Navigate to="/article/list"></Navigate>,
    nodeRef: createRef(null),
  },
  {
    name: "Article",
    path: "/article", //一级路由
    component: LayoutIndex,
    nodeRef: createRef(null),
    meta: {
      title: "文章管理",
      icon: "ic:twotone-article",
      order: 2,
      // role: ['admin'],
      // requireAuth: true,
    },
    children: [
      {
        name: "ArticleList",
        path: "/article/list",
        component: lazy(() => import("@/views/article/list/index.jsx")),
        nodeRef: createRef(null),
        meta: {
          title: "文章列表",
          icon: "material-symbols:format-list-bulleted",
          // role: ['admin'],
          // requireAuth: true,
          keepAlive: true,
        },
      },
      {
        name: "ArticleWrite",
        path: "/article/write",
        component: lazy(() => import("@/views/article/write/index.jsx")),
        nodeRef: createRef(null),
        meta: {
          title: "发布文章",
          icon: "icon-park-outline:write",
          // role: ['admin'],
          // requireAuth: true,
          keepAlive: true,
        },
      },
      {
        name: "ArticleEdit",
        path: "/article/write/:id",
        component: lazy(() => import("@/views/article/write/index.jsx")),
        nodeRef: createRef(null),
        isHidden: true,
        meta: {
          title: "编辑文章",
          icon: "icon-park-outline:write",
          // role: ['admin'],
          // requireAuth: true,
          // keepAlive: true,
        },
      },
      {
        name: "CategoryList",
        path: "/article/category-list",
        component: lazy(() => import("@/views/article/category/index.jsx")),
        nodeRef: createRef(null),
        meta: {
          title: "分类管理",
          icon: "tabler:category",
          // role: ['admin'],
          // requireAuth: true,
          keepAlive: true,
        },
      },
      {
        name: "TagList",
        path: "/article/tag-list",
        component: lazy(() => import("@/views/article/tag")),
        nodeRef: createRef(null),
        meta: {
          title: "标签管理",
          icon: "tabler:tag",
          keepAlive: true,
        },
      },
    ],
  },
  //重定向
  {
    path: "/auth",
    component: () => <Navigate to="/auth/menu"></Navigate>,
    nodeRef: createRef(null),
  },
  {
    name: "Auth",
    path: "/auth",
    component: LayoutIndex,
    nodeRef: createRef(null),
    meta: {
      title: "权限管理",
      icon: "cib:adguard",
      order: 3,
      // role: ['admin'],
      // requireAuth: true,
    },
    children: [
      {
        name: "MenuList",
        path: "/auth/menu",
        component: lazy(() => import("@/views/auth/menu")),
        nodeRef: createRef(null),
        meta: {
          title: "菜单管理",
          icon: "ic:twotone-menu-book",
          keepAlive: true,
        },
      },
      {
        name: "ResourceList",
        path: "/auth/resource",
        component: lazy(() => import("@/views/auth/resource")),
        nodeRef: createRef(null),
        meta: {
          title: "接口管理",
          icon: "mdi:api",
          keepAlive: true,
        },
      },
      {
        name: "RoleList",
        path: "/auth/role",
        component: lazy(() => import("@/views/auth/role")),
        nodeRef: createRef(null),
        meta: {
          title: "角色管理",
          icon: "carbon:user-role",
          keepAlive: true,
        },
      },
    ],
  },
  //重定向
  {
    path: "/error-page",
    component: () => <Navigate to="/error-page/404"></Navigate>,
    nodeRef: createRef(null),
  },
  {
    name: "ErrorPage",
    path: "/error-page",
    component: LayoutIndex,
    nodeRef: createRef(null),
    isHidden: true,
    meta: {
      title: "错误页",
      icon: "mdi:alert-circle-outline",
      order: 99,
    },
    children: [
      {
        name: "ERROR-404",
        path: "/error-page/404",
        component: lazy(() => import("@/views/error-page")),
        nodeRef: createRef(null),
        meta: {
          title: "404",
          icon: "tabler:error-404",
        },
      },
    ],
  },
];

export default routes;
